home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 7 / BBS in a Box - Macintosh - Volume VII (BBS in a Box) (January 1993).iso / Files / Prog / T / THINK C 5.0.3 Update.cpt / THINK C 5.0.3 Update / member.c < prev    next >
Text File  |  1992-08-24  |  1KB  |  96 lines

  1.  
  2. /*
  3.  *  member.c - test class membership
  4.  *
  5.  *  Copyright (c) 1991 Symantec Corporation.  All rights reserved.
  6.  *
  7.  */
  8.  
  9. #define OOPS_PRIVATE
  10. #include "oops.h"
  11.  
  12.  
  13. /*
  14.  *  __member - test class membership
  15.  *
  16.  *  The compiler, for
  17.  *
  18.  *        if (member(obj, C)) ...
  19.  *
  20.  *  generates:
  21.  *
  22.  *            MOVE._    obj->classID,-(SP)
  23.  *            PEA        C
  24.  *            JSR        __member
  25.  *            ADDQ.L    #?,SP
  26.  *            TST.B    D0
  27.  *
  28.  *  This routine tests class membership by searching the superclass
  29.  *  chain for a match on the object's class.
  30.  */
  31.  
  32. static char
  33. dummy()
  34. {
  35.     asm {
  36.  
  37. ;;
  38. ;
  39. ;  char __member(void *class, void *objclass)        //    far version
  40. ;  char __member(void *class, short objclass)        //    near version
  41. ;
  42. ;;
  43.  
  44. extern __member:
  45.  
  46. ;;
  47. ;
  48. ;  set D0 = result (start by assuming "true")
  49. ;  set D1 = class Ref
  50. ;  set D2 = object's class Ref
  51. ;
  52. ;;
  53.  
  54.         moveq    #1,d0
  55.         move.l    4(sp),d1
  56.     #ifdef BASE_REG
  57.         sub.l    BASE_REG,d1
  58.     #endif
  59.         move._    8(sp),d2
  60.  
  61. ;;
  62. ;
  63. ;  compare class Ref's
  64. ;
  65. ;;
  66.  
  67. @1        cmp._    d1,d2
  68.         beq.s    @2                    ;  it's a member
  69.  
  70. ;;
  71. ;
  72. ;  advance to superclass
  73. ;
  74. ;;
  75.  
  76.         movea._    d2,a0
  77.     #ifdef BASE_REG
  78.         adda.l    BASE_REG,a0
  79.     #endif
  80.         moveq    #1,d2
  81.         add.w    (a0)+,d2
  82.         lsl.w    #DSHIFT,d2
  83.         move._    0(a0,d2.w),d2
  84.         bne.s    @1
  85.  
  86. ;;
  87. ;
  88. ;  done
  89. ;
  90. ;;
  91.  
  92.         moveq    #0,d0                ;  it's not a member
  93.  
  94. @2    }
  95. }
  96.